package org.study.springboot.learning.socker;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class EchoClient {
    public static void main(String[] args) throws IOException {
        Socket socket = null;
        PrintWriter pw = null;
        BufferedReader br = null;

        try {
            socket = new Socket("localhost", 18888);
            //PrintWriter作为客户端中输出，给服务端发送数据
            pw = new PrintWriter(socket.getOutputStream(), true);
            //BufferReader作为输入端，接受控制台数据的流
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        } catch (IOException e) {
            System.err.println("Don't know abount host:localhost");
            System.exit(1);
        }
        System.out.println(br.readLine());

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String readLine;
        while ( (readLine = bufferedReader.readLine()) != null) {
            pw.println(readLine);
            System.out.println(br.readLine());
        }
        socket.close();
        pw.close();
        br.close();


    }
}
